/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.micda.moroccoby.front.form;

import com.micda.moroccoby.common.dao.CategorieDAO;
import com.micda.moroccoby.common.dao.ProduitDAO;
import com.micda.moroccoby.common.entities.Categorie;
import com.micda.moroccoby.common.entities.Produit;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Administrateur
 */
@ManagedBean(name = "homeMB")
@RequestScoped
public class HomeBean implements Serializable{

    @EJB
    transient private CategorieDAO categorieDAO;
    @EJB
    transient private ProduitDAO produitDAO;
    
    private List<Categorie> list;
    private Integer idCategorie;
    
    private List<Produit> listProd;
    
    @ManagedProperty(name = "panierBean",value = "#{panierBean}")
    private PanierBean panierBean;

    /**
     * Creates a new instance of HomeBean
     */
    public HomeBean() {
    }

    public void getProduits(){
        
        String categorie = ((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter("idCategorie");
        listProd = produitDAO.getProduitByCategorie(new Integer(categorie));
        System.out.println("########################### listProd" +listProd.size());
    }
    /**
     * @return the list
     */
    public List<Categorie> getList() {
        list = getCategorieDAO().findAll();
        System.out.println("########################### getList "+list.size());
        return list;
    }

    public CategorieDAO getCategorieDAO() {
        return categorieDAO;
    }
    
    public ProduitDAO getProduitDAO(){
        return produitDAO;
    }
    
    public List<Produit> getListProd(){
        return listProd;
    }

    /**
     * @return the idCategorie
     */
    public Integer getIdCategorie() {
        return idCategorie;
    }

    /**
     * @param idCategorie the idCategorie to set
     */
    public void setIdCategorie(Integer idCategorie) {
        System.out.println("################################  ID CAEGO " + idCategorie);
        this.idCategorie = idCategorie;
    }   

    /**
     * @return the panierBean
     */
    public PanierBean getPanierBean() {
        return panierBean;
    }

    /**
     * @param panierBean the panierBean to set
     */
    public void setPanierBean(PanierBean panierBean) {
        this.panierBean = panierBean;
    }
    
}
